﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdArticleFieldExpansion.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdArticleFieldExpansion;
/// <summary>
/// 添加文章字段扩展服务
/// </summary>
public class InsertMdArticleFieldExpansionService : ApiBase<RequestInsertMdArticleFieldExpansionModel>
{
    /// <summary>
    /// 文章字段扩展仓储
    /// </summary>
    public MdArticleFieldExpansionRep mdArticleFieldExpansionRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdArticleFieldExpansionModel();

        model.ArticleId = Parameter.ArticleId;
        model.FieldName = Parameter.FieldName;
        model.FieldValue = Parameter.FieldValue;
        model.FieldType = Parameter.FieldType;
        model.FieldOptions = Parameter.FieldOptions;
        model.CategoryId = Parameter.CategoryId;
        model.Status = Parameter.Status;
        model.DelFlag = "0";
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;
        model.Remark = Parameter.Remark;

        var res = mdArticleFieldExpansionRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = mdArticleFieldExpansionRep.GetMdArticleFieldExpansionById(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

